#!/usr/bin/python
import sympy
zeta = lambda x: sympy.special.zeta_functions.zeta(x).evalf()
e=sympy.var('e')
f=dict()
KR1=dict()
KR1_ms=dict()
G=dict()

def K_ms(expr):
    return expr.expand().series(e,0,0).removeO()

f['ee11-ee-'] = 2./3*(0.75-0.375*e+0.308425*e**2-0.1542125*e**3+0.0887843*e**4)
KR1['ee11-ee-'] = 2/e*f['ee11-ee-']
G['ee11-ee-'] = KR1['ee11-ee-']
KR1_ms['ee11-ee-']=K_ms(KR1['ee11-ee-'])
print 'ee11-ee-', KR1_ms['ee11-ee-']

G['ee12-ee2--'] = 0.5* f['ee11-ee-']
G['ee12-ee2--_k'] = G['ee11-ee-']-G['ee12-ee2--']
KR1['ee12-ee2--'] = G['ee12-ee2--']
KR1['ee12-ee2--_k'] = G['ee12-ee2--_k']

f['e111-e-']=( -0.0208333333358+ 0.0377626005433*e -0.0560792198695*e*e +0.0688067777504*e*e*e)*6
KR1['e111-e-']=1./e*f['e111-e-']
G['e111-e-']=KR1['e111-e-']
KR1_ms['e111-e-']=K_ms(KR1['e111-e-'])

#petlya s arbuzom
f['ee12-ee3-333--']=(-0.0800813809459+ 0.326612350301*e -0.86370930675*e*e)*2
KR1['ee12-ee3-333--']=2./3/e*(f['ee12-ee3-333--']-KR1['ee12-ee2--_k']*f['e111-e-'])
G['ee12-ee3-333--']=(KR1['ee12-ee3-333--']+G['ee12-ee2--_k']*(KR1['e111-e-']))
KR1_ms['ee12-ee3-333--']=K_ms(KR1['ee12-ee3-333--']+G['ee12-ee2--_k']*(KR1['e111-e-']-KR1_ms['e111-e-']))
print 'ee12-ee3-333--', KR1_ms['ee12-ee3-333--']
print 'ee12-ee3-333-- G ', G['ee12-ee3-333--'].series(e,0,0)

#glaz
f['ee12-e22-e-']=(0.750000033922 -1.25396525771*e +1.81337840562*e*e -2.16385799632*e*e*e)/3
KR1['ee12-e22-e-'] = 1./e*(f['ee12-e22-e-']-KR1['ee11-ee-']*f['ee11-ee-'])
G['ee12-e22-e-'] = (KR1['ee12-e22-e-']+G['ee11-ee-']*KR1['ee11-ee-'])
KR1_ms['ee12-e22-e-'] =K_ms (KR1['ee12-e22-e-']+G['ee11-ee-']*(KR1['ee11-ee-']-KR1_ms['ee11-ee-']))
print 'ee12-e22-e-', KR1_ms['ee12-e22-e-']
print 'ee12-e22-e- G ', G['ee12-e22-e-'].series(e,0,2)

f['ee12-e23-e3--'] = (1.171957-2.18139*e+3.2716*e**2-4.053427*e**3)/6
KR1['ee12-e23-e3--'] = f['ee12-e23-e3--']
G['ee12-e23-e3--'] = KR1['ee12-e23-e3--']
G['ee12-e23-e3--_k'] = G['ee12-e22-e-']-G['ee12-e23-e3--']
KR1['ee12-e23-e3--_k'] = G['ee12-e23-e3--_k'] - G['ee11-ee-'] * KR1['ee12-ee2--_k']

f['ee12-e33-3-e-'] = (-0.42192354128752407+0.92732982859489221*e -1.4581446924799937*e*e+ 1.8894022503780528*e*e*e)/6
KR1['ee12-e33-3-e-'] = f['ee12-e33-3-e-']
G['ee12-e33-3-e-'] = KR1['ee12-e33-3-e-']+G['ee12-ee2--']*KR1['ee11-ee-']
G['ee12-e33-3-e-_k'] = G['ee12-e22-e-']-G['ee12-e33-3-e-']
KR1['ee12-e33-3-e-_k'] = G['ee12-e33-3-e-_k'] - G['ee12-ee2--_k'] * KR1['ee11-ee-']

f['ee12-e23-33-e-']=( 1.50000022949 -5.34152475562*e + 13.1756142783*e*e)/6
KR1['ee12-e23-33-e-'] = 2./3./e*(f['ee12-e23-33-e-']-KR1['ee11-ee-']*f['ee12-e22-e-']-KR1['ee12-e22-e-']*f['ee11-ee-'])
G['ee12-e23-33-e-'] = (KR1['ee12-e23-33-e-']+G['ee11-ee-']*KR1['ee12-e22-e-']+G['ee12-e22-e-']*KR1['ee11-ee-'])
KR1_ms['ee12-e23-33-e-'] =K_ms(KR1['ee12-e23-33-e-']+G['ee11-ee-']*(KR1['ee12-e22-e-']-KR1_ms['ee12-e22-e-'])+G['ee12-e22-e-']*(KR1['ee11-ee-']-KR1_ms['ee11-ee-']))
print 'ee12-e23-33-e-', KR1_ms['ee12-e23-33-e-']

f['ee12-e23-44-4-e-']=(-0.58602618313284982+ 2.423028202765134*e -6.4665698374906722*e*e    )/6
KR1['ee12-e23-44-4-e-']=f['ee12-e23-44-4-e-']
G['ee12-e23-44-4-e-'] = KR1['ee12-e23-44-4-e-']+G['ee12-e23-e3--']*KR1['ee11-ee-']
G['ee12-e23-44-4-e-_k'] = G['ee12-e23-33-e-']-G['ee12-e23-44-4-e-']
KR1['ee12-e23-44-4-e-_k'] = G['ee12-e23-44-4-e-_k'] - G['ee11-ee-']*KR1['ee12-e33-3-e-_k']-G['ee12-e23-e3--_k']*KR1['ee11-ee-']

#glaz s arbuzom 1
f['ee12-e33-444-e4--']= (0.164311173228 -1.10445951269*e)/1.
KR1['ee12-e33-444-e4--'] = 1./2/e*(f['ee12-e33-444-e4--']-KR1['ee12-e33-3-e-_k']*f['e111-e-']- KR1['ee12-ee3-333--']*f['ee11-ee-'])
G['ee12-e33-444-e4--'] = (KR1['ee12-e33-444-e4--']+G['ee12-e33-3-e-_k']*KR1['e111-e-']+G['ee12-ee3-333--']*KR1['ee11-ee-'] -
    G['ee12-ee2--_k']*KR1['e111-e-']*KR1['ee11-ee-'])
#print K_ms(KR1['ee12-e33-444-e4--'])
#print K_ms(G['ee12-e33-444-e4--'])
KR1_ms['ee12-e33-444-e4--'] = K_ms(KR1['ee12-e33-444-e4--']+G['ee12-e33-3-e-_k']*(KR1['e111-e-']-KR1_ms['e111-e-'])+G['ee12-ee3-333--']*(KR1['ee11-ee-']-KR1_ms['ee11-ee-']) -
    G['ee12-ee2--_k']*(KR1['e111-e-']*KR1['ee11-ee-']-KR1_ms['e111-e-']*KR1_ms['ee11-ee-']))


#glaz s arbuzom 2
f['ee12-e23-e4-444--']=(-0.266846639038+ 1.72406174058*e)/1.
KR1['ee12-e23-e4-444--'] = 1./2/e*(f['ee12-e23-e4-444--']-KR1['ee11-ee-']*f['ee12-ee3-333--']-KR1['ee12-e23-e3--_k']*f['e111-e-'])
G['ee12-e23-e4-444--'] = (KR1['ee12-e23-e4-444--']+G['ee11-ee-']*KR1['ee12-ee3-333--']+G['ee12-e23-e3--_k']*KR1['e111-e-'])
KR1_ms['ee12-e23-e4-444--'] = K_ms(KR1['ee12-e23-e4-444--']+G['ee11-ee-']*(KR1['ee12-ee3-333--']-KR1_ms['ee12-ee3-333--'])+G['ee12-e23-e3--_k']*(KR1['e111-e-']-KR1_ms['e111-e-']))

print 'glaz s arbuzom', K_ms(2*KR1_ms['ee12-e23-e4-444--']  + 2*KR1_ms['ee12-e33-444-e4--'])

#n4
f['ee12-e23-44-555-e5--']=(0.396730628385)/1.
KR1['ee12-e23-44-555-e5--'] = 2./5/e*(f['ee12-e23-44-555-e5--']-KR1['ee11-ee-']*f['ee12-e33-444-e4--']-KR1['ee12-e23-44-4-e-_k']*f['e111-e-']
    - KR1['ee12-e23-e4-444--']*f['ee11-ee-'])
G['ee12-e23-44-555-e5--'] = (KR1['ee12-e23-44-555-e5--']+G['ee11-ee-']*KR1['ee12-e33-444-e4--']+G['ee12-e23-44-4-e-_k']*KR1['e111-e-']
    + G['ee12-e23-e4-444--']*KR1['ee11-ee-'] - G['ee12-e23-e3--_k']*KR1['ee11-ee-']*KR1['e111-e-'])
KR1_ms['ee12-e23-44-555-e5--'] = K_ms(KR1['ee12-e23-44-555-e5--']+G['ee11-ee-']*(KR1['ee12-e33-444-e4--']-KR1_ms['ee12-e33-444-e4--'])+G['ee12-e23-44-4-e-_k']*(KR1['e111-e-']-KR1_ms['e111-e-'])
    + G['ee12-e23-e4-444--']*(KR1['ee11-ee-']-KR1_ms['ee11-ee-']) - G['ee12-e23-e3--_k']*(KR1['ee11-ee-']*KR1['e111-e-']-KR1_ms['ee11-ee-']*KR1_ms['e111-e-']))

print "n4"
print 'ee12-e23-44-555-e5--', K_ms(KR1_ms['ee12-e23-44-555-e5--'])
print 'ee12-e23-44-555-e5-- orig ',(-(2./5*zeta(3)-103./160)/e+37./240/e/e-19./20/e/e/e+7./15/e/e/e/e)/32

f['ee12-e34-334-e--'] = (-0.7765174300247536+ 3.2172644355174445*e -8.5984508978396068*e*e)/6
KR1['ee12-e34-334-e--'] = f['ee12-e34-334-e--']
G['ee12-e34-334-e--'] = KR1['ee12-e34-334-e--']+G['ee12-e23-e3--']*KR1['ee11-ee-']
G['ee12-e34-334-e--_k'] = G['ee12-e23-33-e-']-G['ee12-e34-334-e--']
KR1['ee12-e34-334-e--_k'] = G['ee12-e34-334-e--_k']- G['ee11-ee-']*KR1['ee12-e33-3-e-_k']-G['ee12-e23-e3--_k']*KR1['ee11-ee-']

#n5
f['ee12-e34-335-e-555--']=( 0.430294653269)/1.
KR1['ee12-e34-335-e-555--'] = 2./5/e*(f['ee12-e34-335-e-555--']-KR1['ee11-ee-']*f['ee12-e33-444-e4--']-KR1['ee12-e34-334-e--_k']*f['e111-e-']-
                                      KR1['ee12-e23-e4-444--']*f['ee11-ee-'])
G['ee12-e34-335-e-555--'] = (KR1['ee12-e34-335-e-555--']+G['ee11-ee-']*KR1['ee12-e33-444-e4--']+G['ee12-e34-334-e--_k']*KR1['e111-e-']+
                                      G['ee12-e23-e4-444--']*KR1['ee11-ee-']-G['ee12-e23-e3--_k']*KR1['ee11-ee-']*KR1['e111-e-'])
KR1_ms['ee12-e34-335-e-555--'] = K_ms(KR1['ee12-e34-335-e-555--']+G['ee11-ee-']*(KR1['ee12-e33-444-e4--']-KR1_ms['ee12-e33-444-e4--'])+G['ee12-e34-334-e--_k']*(KR1['e111-e-']-KR1_ms['e111-e-'])+
                                      G['ee12-e23-e4-444--']*(KR1['ee11-ee-']-KR1_ms['ee11-ee-'])-G['ee12-e23-e3--_k']*(KR1['ee11-ee-']*KR1['e111-e-']-KR1_ms['ee11-ee-']*KR1_ms['e111-e-']))
print "n5"
print 'ee12-e34-335-e-555--', K_ms(KR1_ms['ee12-e34-335-e-555--'])
print 'ee12-e34-335-e-555-- orig ',((103./160)/e+37./240/e/e-19./20/e/e/e+7./15/e/e/e/e)/32


f['ee12-e34-3-44-e-']=(0.12898140999863736 -0.61913016957675104*e+ 1.7922955720698273*e*e)/6
KR1['ee12-e34-3-44-e-']=f['ee12-e34-3-44-e-']
G['ee12-e34-3-44-e-']=KR1['ee12-e34-3-44-e-']+G['ee12-ee2--']*KR1['ee12-e22-e-']+G['ee12-e33-3-e-']*KR1['ee11-ee-']
G['ee12-e34-3-44-e-_k']=G['ee12-e23-33-e-']-G['ee12-e34-3-44-e-']
KR1['ee12-e34-3-44-e-_k'] = G['ee12-e34-3-44-e-_k']-G['ee12-ee2--_k']*KR1['ee12-e22-e-']-G['ee12-e33-3-e-_k']*KR1['ee11-ee-']

#n6

f['ee12-333-445-5-e5-e-']=( -0.0831278570711)/1.
KR1['ee12-333-445-5-e5-e-']=2./5/e*(f['ee12-333-445-5-e5-e-']-KR1['ee12-ee3-333--']*f['ee12-e22-e-']-KR1['ee12-e33-444-e4--']*f['ee11-ee-']
    -KR1['ee12-e34-3-44-e-_k']*f['e111-e-'])
G['ee12-333-445-5-e5-e-']=(KR1['ee12-333-445-5-e5-e-']+G['ee12-ee3-333--']*KR1['ee12-e22-e-']+G['ee12-e33-444-e4--']*KR1['ee11-ee-']
    +G['ee12-e34-3-44-e-_k']*KR1['e111-e-']-G['ee12-e33-3-e-_k']*KR1['e111-e-']*KR1['ee11-ee-']-G['ee12-ee2--_k']*KR1['e111-e-']*KR1['ee12-e22-e-'])
KR1_ms['ee12-333-445-5-e5-e-']=K_ms(KR1['ee12-333-445-5-e5-e-']+G['ee12-ee3-333--']*(KR1['ee12-e22-e-']-KR1_ms['ee12-e22-e-'])+G['ee12-e33-444-e4--']*(KR1['ee11-ee-']-KR1_ms['ee11-ee-'])
    +G['ee12-e34-3-44-e-_k']*(KR1['e111-e-']-KR1_ms['e111-e-'])-G['ee12-e33-3-e-_k']*(KR1['e111-e-']*KR1['ee11-ee-']-KR1_ms['e111-e-']*KR1_ms['ee11-ee-'])-G['ee12-ee2--_k']*(KR1['e111-e-']*KR1['ee12-e22-e-']-KR1_ms['e111-e-']*KR1_ms['ee12-e22-e-']))

print "n6"
print 'ee12-333-445-5-e5-e-', K_ms(KR1_ms['ee12-333-445-5-e5-e-'])
print 'ee12-333-445-5-e5-e- orig ',(-(11./192)/e+33./80/e/e-11./12/e/e/e+3./5/e/e/e/e)/32


f['ee12-e23-34-e4--']=(2.6047408949686495 -9.7441856988590025*e + 24.658379975369712*e*e)/12.
KR1['ee12-e23-34-e4--']=f['ee12-e23-34-e4--']
G['ee12-e23-34-e4--']=KR1['ee12-e23-34-e4--']
G['ee12-e23-34-e4--_k']=G['ee12-e23-33-e-']-G['ee12-e23-34-e4--']
KR1['ee12-e23-34-e4--_k']=G['ee12-e23-34-e4--_k']-G['ee11-ee-']*KR1['ee12-e23-e3--_k']-G['ee12-e22-e-']*KR1['ee12-ee2--_k']


#n16

f['ee12-e23-34-e5-555--']=(-0.858686981226)/2
KR1['ee12-e23-34-e5-555--']=2./5/e*(f['ee12-e23-34-e5-555--']-KR1['ee12-e23-34-e4--_k']*f['e111-e-']-KR1['ee12-e22-e-']*f['ee12-ee3-333--']
                                    -KR1['ee11-ee-']*f['ee12-e23-e4-444--'])
G['ee12-e23-34-e5-555--']=(KR1['ee12-e23-34-e5-555--']+G['ee12-e23-34-e4--_k']*KR1['e111-e-']+G['ee12-e22-e-']*KR1['ee12-ee3-333--']
                                    +G['ee11-ee-']*KR1['ee12-e23-e4-444--'])
KR1_ms['ee12-e23-34-e5-555--']=K_ms(KR1['ee12-e23-34-e5-555--']+G['ee12-e23-34-e4--_k']*(KR1['e111-e-']-KR1_ms['e111-e-'])+G['ee12-e22-e-']*(KR1['ee12-ee3-333--']-KR1_ms['ee12-ee3-333--'])
                                    +G['ee11-ee-']*(KR1['ee12-e23-e4-444--']-KR1_ms['ee12-e23-e4-444--']))
print "n16"
print 'ee12-e23-34-e5-555--', K_ms(KR1_ms['ee12-e23-34-e5-555--'])
print 'ee12-e23-34-e5-555-- orig ',(-(2387./960)/e+41./15/e/e-13./10/e/e/e+4./15/e/e/e/e)/32

print 'KR1 ee12-e23-33-e-_k (sum)', K_ms(KR1['ee12-e23-34-e4--_k']*2+2*KR1['ee12-e34-3-44-e-_k']+KR1['ee12-e34-334-e--_k']+KR1['ee12-e23-44-4-e-_k'])
print 'G ee12-e23-33-e-_k (sum)', K_ms(G['ee12-e23-34-e4--_k']*2+2*G['ee12-e34-3-44-e-_k']+G['ee12-e34-334-e--_k']+G['ee12-e23-44-4-e-_k'])
print 'G ee12-e23-33-e-_ (sum)', K_ms(G['ee12-e23-34-e4--']*2+2*G['ee12-e34-3-44-e-']+G['ee12-e34-334-e--']+G['ee12-e23-44-4-e-'])
print 'f ee12-e23-33-e-_ (sum)', (f['ee12-e23-34-e4--']*2+2*f['ee12-e34-3-44-e-']+f['ee12-e34-334-e--']+f['ee12-e23-44-4-e-'])
print 'f ee12-e23-33-e- orig', f['ee12-e23-33-e-']

print 'KR1 ee11-ee- (sum)', KR1['ee11-ee-'].series(e,0)
print 'f ee11-ee-_ (sum)', 2*G['ee12-ee2--'].series(e,0)

print 'KR1 ee12-e22-e- (sum)', KR1['ee12-e22-e-'].series(e,0)
print 'f ee12-e22-e-_ (sum)', (2*G['ee12-e33-3-e-']+2*G['ee12-e23-e3--']).series(e,0)


#G['ee12-3-3-e-__']=

#ee12-ee3-333--_k #1

f['ee12-3-444-ee4--'] = (0.0024203139940893069 -0.0096656013364534495*e+ 0.024784195142836401*e*e)*2
f['ee12-3-444-ee4--'] = (0.0072610286308025102 -0.028998613952457342*e+ 0.074347001136005467*e*e)*2/3

KR1['ee12-3-444-ee4--'] = f['ee12-3-444-ee4--']
G['ee12-3-444-ee4--']=KR1['ee12-3-444-ee4--']+KR1['ee12-ee2--_k']*f['e111-e-']
G['ee12-3-444-ee4--_k']=G['ee12-ee3-333--']-G['ee12-3-444-ee4--']
print G['ee12-3-444-ee4--'].series(e,0,0)
print G['ee12-3-444-ee4--_k'].series(e,0,0)

f['ee12-ee3-334-4--'] = (-0.010235817916449645 -0.78295130585229389*e+ 7.6725761539128765*e*e)*2/3
f['ee12-ee3-334-4--'] = (-0.019548323579780591+ 0.096139605075776041*e -0.27593220771144233*e*e)*2/3
KR1['ee12-ee3-334-4--'] = f['ee12-ee3-334-4--']
G['ee12-ee3-334-4--']=KR1['ee12-ee3-334-4--']+KR1['ee12-ee2--']*3*f['ee12-e22-e-']
G['ee12-ee3-334-4--_k']=G['ee12-ee3-333--']-G['ee12-ee3-334-4--']
print G['ee12-ee3-334-4--_k'].series(e,0,0)

print (3*G['ee12-3-444-ee4--_k']+3*G['ee12-ee3-334-4--_k']).series(e,0,3)
print (3*G['ee12-3-444-ee4--']+3*G['ee12-ee3-334-4--']).series(e,0,3)
print (3*f['ee12-3-444-ee4--']+3*f['ee12-ee3-334-4--']).series(e,0,3)



KR1['ee12-3-444-ee4--_k'] = G['ee12-3-444-ee4--_k']-G['ee12-3-3-e-_k_k']*KR1['e111-e-']